
//加载方法
$(function (){
    $.ajax({
        url:"/DHMApply/numberCheckTag0",
        type: "get",
        success:function (data){
            $("#weishenhe").html(data)
        }
    })
    $.ajax({
        url:"/DHMApply/numberCheckTag1",
        type: "get",
        success:function (data){
            $("#yitongguo").html(data)
        }
    })
    $.ajax({
        url:"/DHMApply/numberCheckTag2",
        type: "get",
        success:function (data){
            $("#weitongguo").html(data)
        }
    })
    //模糊查询的方法，生成表格
    $("#applyTable").bootstrapTable({
        method:"get",
        contentType:"application/json;charset=utf-8",
        url: "/DHMApply/findLike",
        striped: true,
        pageNumber:1,
        pagination:true,
        sidePagination:"server",//设置服务端分页还是客户端分页
        pageSize:5,//页大小
        pageList:[3,5,9],//每页显示的条数
        queryParams:function (params) {
            return {
                pageNum: (params.offset / params.limit) + 1,
                pageSize:params.limit,
                applyId:$("#applyId").val(),
                productName:$("#productName").val(),
                startTime:$("#startTime").val(),
                endTime:$("#endTime").val(),
            }
        },
        columns:[
            {title:'生产计划编号',field:'applyId',align:'center'},
            {title:'计划设计人',field:'designer',align:'center'},
            {title:'登记人',field:'register',align:'center'},
            {title:'登记时间',field:'registerTime',align:'center'},
            {title:'审核时间',field:'checkTime',align:'center'},
            {title:'备注',field:'remark',align:'center'},
            {title:'审核状态',field:'checkTag',align:'center',
                formatter:function (value,row,index) {
                    if (value=='0'){
                        return '<font color="orange">待审核</font>';
                    }else if (value=='1'){
                        return '<font color="green">审核通过</font>';
                    }else{
                        return '<font color="red">审核未通过</font>';
                    }
                }
            },
            {title:'查看详情',field:'applyId',align:'center',
                formatter:function (value,row,index) {
                    let btn="<button class='btn btn-info' onclick='watch("+value+")'>查看</button>";
                    return btn;
                }
            },
        ]
    })
})

//点击查询
function queryLike(){
    $("#applyTable").bootstrapTable("refresh");
}

//查看详情
function watch(applyId){
    $(".div1").hide();
    $(".div2").show();
    $("#dengji").html("");
    $("#shenhe").html("");
    $("#remark").html("");
    $("#checkSuggestion").html("");
    $.ajax({
        url: "/DHMApply/byApplyId",
        type:"get",
        data:{
            applyId:applyId,
        },
        dataType:"json",
        success:function (data){
            let tr ="";
            for (let i = 0; i < data.length; i++) {
                tr +="<tr>\n" +
                    "                <td>"+data[i].productName+"</td>\n" +
                    "                <td>"+data[i].productId+"</td>\n" +
                    "                <td>"+data[i].productDescribe+"</td>\n" +
                    "                <td class='shuliang'>"+data[i].amount+"</td>\n" +
                    "                <td>"+data[i].dFile.amoutUnil+"</td>\n" +
                    "                <td>"+data[i].dFile.realCostPrice+"</td>\n" +
                    "                <td class=\"xiaoji\">"+data[i].amount*data[i].dFile.realCostPrice+"</td>\n" +
                    "            </tr>";
            }
            $("#tbody").html(tr);

            //获取数量和小计
            let xiaoji = $(".xiaoji");
            let amounts = $(".shuliang");

            //定义总数量和总金额
            let totalCount=0;
            let totalPrice=0;
            amounts.each(function (i,e){
                totalCount+=parseInt($(e).html());
            })
            xiaoji.each(function (i,e){
                totalPrice+=parseFloat($(e).html());
            })

            $("#totalCount").html(totalCount);
            $("#totalPrice").html(totalPrice);

            //相关信息传入
            $("#dengji").html(data[0].register);
            $("#shenhe").html(data[0].checker);
            $("#remark").html(data[0].remark);
            $("#checkSuggestion").html(data[0].checkSuggestion);
        }
    })
}


//返回列表
function fanhuiliebiao(){
    $(".div1").show();
    $(".div2").hide();
}